home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1991 / Feb 91 / MacApp.Tech$ 2⁄15⁄91 / 2947-Re overloading vs. o-Feb91 < prev    next >
Encoding:
Text File  |  1991-03-06  |  1.7 KB  |  51 lines  |  [TEXT/GEOL]

  1. Item    0054226                         13-Feb-91        09:45PST
  2.  
  3. From:   ALGER                           Alger, Jeff,VCA
  4.  
  5. To:     LALEKERMAC                      CSX Technology, W Laleker,SSF,PAS
  6.         MACAPP.TECH$                    MacApp Technical
  7.  
  8. ------------------------------------------------------------------------------
  9.  
  10. Sub:    Re: overloading vs. overriding
  11.  
  12. Earl,
  13.  
  14. What you have described is not inheritance.  The method B::A does not have
  15. anything to do with A::A.  The terms overloading and overriding are frequently
  16. confused, so let me attempt to clear up the terms.  Both use polymorphism - the
  17. ability to give several different functions the same name - but there the
  18. similarity ends.
  19.  
  20. • Overloading applies WITHIN a single class and has nothing to do with
  21. inheritance.  Overloading allows you to use the same name for several different
  22. methods of a class, each of which has a different calling sequence.  This is
  23. overloading:
  24.  
  25. class foo {
  26.    void x(void); // first method
  27.    void x(int); // second method, same name, different args
  28. };
  29.  
  30. Notice that both implementations of x() are within the same class.
  31.  
  32. • Overriding applies to inherited methods and requires a common interface
  33. (i.e., argument list).  This is overriding:
  34.  
  35. class foo {
  36.    virtual void x(void); // foo version of method
  37. };
  38.  
  39. class bar: public foo {
  40.    virtual void x(void); // bar version of method
  41. };
  42.  
  43. In all cases, the best way to conceptualize your design is to initially assign
  44. unique names to all implementations, then layer overloading and overriding on
  45. top of that design to achieve an optimal interface.  It's easy to go batty
  46. trying to "design-in" polymorphism at an early stage.
  47.  
  48. Hope this helps,
  49. Jeff Alger
  50.  
  51.